﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace 处理Html中的占位符
{
    public class Program
    {
        static void Main(string[] args)
        {
            //读取Html文本，并且取出其中大括号包裹的字段
            HandleHtml("53");
        }
        public static void HandleHtml(string cdaCode)
        {
            var htmlPath = "D:\\Aewell\\Code\\共享文档\\doc-api\\src\\OpenAuth.App\\HtmlTemplate\\"+cdaCode+".html";
            var html = File.ReadAllText(htmlPath);
            var headPara = new List<string>();
            var regex = new Regex(@"\{.*?\}");
            if (regex.IsMatch(html))
            {
                MatchCollection matches = regex.Matches(html);
                foreach (Match match in matches)
                {
                    headPara.Add(match.Value.Trim('{', '}'));
                }
            }
            var noNeed = new List<string>() {
                      "患者年龄",
                    "患者年龄单位",
                    "出生日期",
                    "电子申请单编号",
                    "就诊医师",
                    "责任医生",
                    "记录日期时间",
                    "门（急）诊号标识",
                    "开立科室",
                    "开立日期",
                    "开立医生",
                    "处方调配药剂师",
                    "处方核对药剂师",
                    "处方发药药剂师",
                    "处方审核药剂师",
                    "处方编号",
                    "患者姓名",
                    "保管机构代码",
                    "保管机构名称",
                    "患者性别",
                    "患者电话",
                    "患者身份证号",
            };
            var sb = new StringBuilder();
            foreach (var item in headPara)
            {
                if (!noNeed.Contains(item))
                {
                    sb.Append(item.ToString()+"\r\n");
                }
            }
            var filePath = "C:\\Users\\limen\\Downloads\\temp.txt";
            File.WriteAllText(filePath, sb.ToString());
        }
    }
}
